package com.devilvan.betrice.poetry.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.devilvan.betrice.poetry.dto.PoetryDetailDto;
import com.devilvan.betrice.poetry.po.PoetryDetailPo;
import com.devilvan.betrice.poetry.service.PoetryDetailService;
import com.devilvan.betrice.poetry.mapper.PoetryDetailMapper;
import com.devilvan.betrice.poetry.repository.PoetryDetailRepository;
import com.devilvan.betrice.util.UCopy;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
* @author Evad.Wu
* @Description 古诗文网-内容信息表 业务逻辑类
* @date 2022-11-29
*/
@Service
public class PoetryDetailServiceImpl extends ServiceImpl<PoetryDetailMapper, PoetryDetailPo> implements PoetryDetailService {
    @Resource(name = "poetryDetailRepository")
    private PoetryDetailRepository poetryDetailRepository;

    @Override
    public PoetryDetailPo saveUpdate(PoetryDetailDto poetryDetailDto) {
        PoetryDetailPo poetryDetailPo = new PoetryDetailPo();
        UCopy.fullCopy(poetryDetailDto, poetryDetailPo);
        return poetryDetailRepository.saveAndFlush(poetryDetailPo);
    }

    @Override
    public List<PoetryDetailPo> saveUpdateBatch(List<PoetryDetailDto> list) {
        List<PoetryDetailPo> poetryDetailPoList = UCopy.fullCopyCollections(list, PoetryDetailPo.class);
        return poetryDetailRepository.saveAllAndFlush(poetryDetailPoList);
    }
}
